﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using The_LarX;

namespace LarX_Editor
{
    public partial class LanguageListMaker : Form
    {
        public LanguageListMaker()
        {
            InitializeComponent();
        }

        private void AddFontButton_Click(object sender, EventArgs e)
        {
            // Inicia um OpenFileDialog, para o usuário abri um arquivo de Lingua
            OpenFileDialog openFileDialog1 = new OpenFileDialog();
            openFileDialog1.Filter = "Lar Language Files|*.larlang";
            openFileDialog1.Title = "Select a Lar Language File";
            openFileDialog1.Multiselect = true;

            // Se o usuário clicou em OK
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                string[] files = openFileDialog1.SafeFileNames;

                string[] s = new string[files.Length];

                for (int i = 0; i < files.Length; i++)
                {
                    s[i] = files[i].Replace(".spritefont", "");
                }

                FontsList.Items.AddRange(s);
            }
        }
        private void RemoveButton_Click(object sender, EventArgs e)
        {
            if (FontsList.SelectedItem != null)
            {
                FontsList.Items.Remove(FontsList.SelectedItem);
            }
        }

        private void SaveButton_Click(object sender, EventArgs e)
        {
            List<String> s = new List<string>();

            for (int i = 0; i < FontsList.Items.Count; i++)
            {
                string l = (string)FontsList.Items[i];
                s.Add(l.Replace(".larlang", ""));
            }

            // Inicia um SaveFileDialog, para o usuário salvar o arquivo de Lingua
            SaveFileDialog saveFileDialog = new SaveFileDialog();
            saveFileDialog.Filter = "Lar Language List File|*.larlanguages";
            saveFileDialog.Title = "Find the Place";

            // Se o usuário clicou em OK
            if (saveFileDialog.ShowDialog() == DialogResult.OK)
            {
                Serializer.SaveCustom(s, saveFileDialog.FileName);
            }
        }
    }
}
